package com.mcp.converter.shared.response.analysis;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.Getter;

import java.util.List;

/**
 * ifp框架分析上下文，封装分析过程中的数据
 * @author zengxiong
 */
public class IfpAnalysisContext {
    @Getter
    private final JsonNode extractNode;
    @Getter
    private final List<String> validSqls;
    @Getter
    private final List<JsonNode> sqlDetailsList;
    @Getter
    private final String xmlFilePath;
    @Getter
    private final String errorResponse;
    private final boolean hasError;
    
    private IfpAnalysisContext(JsonNode extractNode, List<String> validSqls, 
                              List<JsonNode> sqlDetailsList, String xmlFilePath,
                              String errorResponse, boolean hasError) {
        this.extractNode = extractNode;
        this.validSqls = validSqls;
        this.sqlDetailsList = sqlDetailsList;
        this.xmlFilePath = xmlFilePath;
        this.errorResponse = errorResponse;
        this.hasError = hasError;
    }
    
    /**
     * 创建成功的分析上下文
     */
    public static IfpAnalysisContext success(JsonNode extractNode, List<String> validSqls,
                                            List<JsonNode> sqlDetailsList, String xmlFilePath) {
        return new IfpAnalysisContext(extractNode, validSqls, sqlDetailsList, xmlFilePath, null, false);
    }
    
    /**
     * 创建包含错误的分析上下文
     */
    public static IfpAnalysisContext withError(String errorResponse) {
        return new IfpAnalysisContext(null, null, null, null, errorResponse, true);
    }

    public boolean hasError() {
        return hasError;
    }
}